package cn.edu.hnu.matching.config;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class SaTokenConfig implements WebMvcConfigurer {
    // 注册 Sa-Token 的拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册路由拦截器，自定义认证规则 
        registry.addInterceptor(new SaInterceptor(handler -> {
            // 登录校验
            SaRouter.match("/**")
                    .notMatch("/user/wxlogin/**",
                            "/doc.html", "/v3/api-docs/**", "/swagger-ui.html", "/webjars/**")
                    .check(r -> StpUtil.checkLogin());
            
        })).addPathPatterns("/**");
    }
}
